define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'lejiaytj/user/index' + location.search,
                    add_url: 'lejiaytj/user/add',
                    edit_url: 'lejiaytj/user/edit',
                    del_url: 'lejiaytj/user/del',
                    multi_url: 'lejiaytj/user/multi',
                    table: 'user',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'user_id',
                sortName: 'user_id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'name', title: __('Name')},
                        {field: 'sex', title: __('Sex')},
                        {field: 'nation', title: __('Nation')},
                        {field: 'birthday', title: __('Birthday')},
                        {field: 'idnumber', title: __('Idnumber')},
                        {field: 'idnumber_status', title: __('Idnumber_status')},
                        {field: 'age', title: __('Age')},
                        {field: 'address', title: __('Address')},
                        {field: 'ctime', title: __('Ctime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'dev_no', title: __('Dev_no')},
                        {field: 'vender_id', title: __('Vender_id')},
                        {field: 'tel', title: __('Tel')},
                        {field: 'lxr', title: __('Lxr')},
                        {field: 'lxrtel', title: __('Lxrtel')},
                        {field: 'tangnb', title: __('Tangnb')},
                        {field: 'gaoxy', title: __('Gaoxy')},
                        {field: 'guanxb', title: __('Guanxb')},
                        {field: 'village_id', title: __('Village_id')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});